#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct lString {
	int max_len;
	int n;
	char *s;
} lString;

char *lstrstr(char *s1, char *s2)
{
	int i,j,ch;
	int flag;
	int s1_len = strlen(s1);
	int s2_len = strlen(s2);
	int len =s1_len - s2_len;
	ch = s2[0];
	for (i = 0; i < len; i++)
	{
/*		
		if (s1[i] != ch)
		{
			continue;
		}
*/
		for (j = 0; j < s2_len; j++)
		{
			if (s1[i+j] != s2[j])
			{
				break;
			}
		}

		if (j == s2_len)
		{
			printf("find pos: %d\n", i+1);
			break;
		}	
	}

	return NULL;
}

char *lstrstr2(char *s1, char *s2)
{
	int i,j,ch;
	int flag;
	int s1_len = strlen(s1);
	int s2_len = strlen(s2);

	int skip = 0;
	ch = s2[0];
	for (i = 0; i < s1_len - s2_len; i++)
	{
		if (s1[i] != ch)
		{
			continue;
		}

		skip = 0;
		for (j = 1; j < s2_len; j++)
		{
			if (s1[i+j] != s2[j])
			{
				break;
			}

			skip += 1;
		}

		if (j == s2_len)
		{
			printf("find pos: %d\n", i+1);
			break;
		}

		i += skip;
	}

	return NULL;
}

int main(int argc, char *argv[])
{
	lString str;

	char s1[128]="hl99ldh9999999uuuuuuuuudfasdfasasdfasdfsdfasgfdhdllllhhhhlhhdhuiisdfdfjjjkkldh00";
	char s2[5]="ldh";
	lstrstr(s1, s2);

	lstrstr2(s1, s2);

	return 0;
}